#include "stm32f4xx.h"
#include "sys.h"
#include "delay.h"
#include "led.h" 
#include "lcd_init.h"
#include "lcd.h"
#include "pic.h"
#include "foc_algorithm.h"
#include "adc.h"
#include "pwm.h"
#include "drv8301.h"
#include "enconder.h"
#include "gmr.h"
/****************************************************************************/
/****************************************************************************/
/*****************************************************************************/
float speed_test_2;

int main(void)
{
	delay_init(168);
	drv8301_init();
	TLE5012B_Init();
	GMR_Init();
	delay_ms(100);	
	true_angle = ENC_Get_Electrical_Angle();
	delay_ms(100);	
	RUN = 1;
	
	LCD_Init();//LCD初始化
	LED_Init();
	TIM1_PWM_Init();
	Adc_Init();
	
	LCD_Fill(0,0,LCD_W,LCD_H,BLACK);
	LCD_ShowString(20,20,"FOC_TEST_1",RED,WHITE,16,1);
	get_offset_flag = 1;
	
	Current_D_PID.P_Gain = D_PI_P;
  Current_D_PID.I_Gain = D_PI_I;
  Current_D_PID.B_Gain = D_PI_KB;
  Current_D_PID.Max_Output = D_PI_UP_LIMIT;
  Current_D_PID.Min_Output = D_PI_LOW_LIMIT;
  Current_D_PID.I_Sum = 0.0f;
  
  Current_Q_PID.P_Gain = Q_PI_P;
  Current_Q_PID.I_Gain = Q_PI_I;
  Current_Q_PID.B_Gain = Q_PI_KB;
  Current_Q_PID.Max_Output = Q_PI_UP_LIMIT;
  Current_Q_PID.Min_Output = Q_PI_LOW_LIMIT;
  Current_Q_PID.I_Sum = 0.0f;
	
	Speed_Pid.P_Gain = SPEED_PI_P;
  Speed_Pid.I_Gain = SPEED_PI_I;
  Speed_Pid.B_Gain = SPEED_PI_KB;
  Speed_Pid.Max_Output = SPEED_PI_UP_LIMIT;
  Speed_Pid.Min_Output = SPEED_PI_LOW_LIMIT;
  Speed_Pid.I_Sum = 0.0f;
	
	while(1)
	{
//		LCD_ShowFloatNum1(120,40,FOC_Input.Udc,6,RED,BLACK,24);
//		LCD_ShowFloatNum1(120,70,true_angle,6,RED,BLACK,24);
//		LCD_ShowFloatNum1(120,100,speed_test,6,RED,BLACK,24);	
////		speed_test_2 = Conversion_Speed1();
//		drv8301_protection();
		delay_ms(100);
	}
}
/*****************************************************************************/
